package net.wicp.tams.commons.spring;

import java.util.Properties;

import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import net.wicp.tams.commons.Conf;
import net.wicp.tams.commons.Conf.InitCallback;

/***
 * spring cloud需要用到的配置信息加载
 * 
 * @author zhoujunhui
 *
 */
@Configuration
public class SpringConfiguration {
	@Configuration
	protected static class MidConfiguration implements EnvironmentAware {

		@Override
		public void setEnvironment(Environment environment) {
			final Properties inputpamas = new Properties();
			Properties zaProps = Conf.copyProperties();
			for (Object key : zaProps.keySet()) {
				String keystr = String.valueOf(key);
				if (environment.containsProperty(keystr)) {
					inputpamas.put(keystr, environment.getProperty(keystr));
				}
			}
			Conf.addCallBackInit("conf-microservices", new InitCallback() {
				@Override
				public Properties doInitConf() {
					return inputpamas;
				}
			});
		}
	}
}